package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApAuthorMapper;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.pojos.ApAuthor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 嘉德罗斯
 * @date 2021/11/20
 */
@Service
@Transactional
public class ApAuthorServiceImpl extends ServiceImpl<ApAuthorMapper,ApAuthor> implements ApAuthorService {

    @Autowired
    private ApAuthorMapper apAuthorMapper;



    @Override
    public Map load(List<Long> ids) {
        LambdaQueryWrapper<ApAuthor> apAuthorLambdaQueryWrapper= new LambdaQueryWrapper<>();
        apAuthorLambdaQueryWrapper.in(ApAuthor::getUserId,ids);
        List<ApAuthor> apAuthors = apAuthorMapper.selectList(apAuthorLambdaQueryWrapper);
        Map<Long,String> map = new HashMap<>();
        for (ApAuthor apAuthor : apAuthors) {
            map.put(Long.valueOf(apAuthor.getUserId()),apAuthor.getName());
        }
        return map;
    }
}
